package com.dkhseep.bigevent.controller;

import com.dkhseep.bigevent.pojo.Category;
import com.dkhseep.bigevent.pojo.Result;
import com.dkhseep.bigevent.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 功能:
 * 作者:Dksheep
 * 日期:2024/10/1010:21
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @PostMapping("")
    public Result addCategory(@RequestBody @Validated(Category.Add.class) Category category) {
        System.out.println(category.getCategoryName());
        categoryService.addCategory(category);
        return Result.success();
    }
    @GetMapping("")
    public Result<List<Category>>getCategoryList() {
        return Result.success(categoryService.getCategoryList());
    }
    @PutMapping("")
    public Result updateCategory(@RequestBody @Validated(Category.Update.class) Category category) {
        categoryService.updateCategory(category);
        return Result.success();
    }
    @DeleteMapping
    public Result deleteCategory(@RequestParam int id){
        categoryService.deleteCategory(id);
        return Result.success();
    }
    @GetMapping("/detail")
    public Result<Category>getCategoryDetail(@RequestParam int id){
        return Result.success(categoryService.getCategoryDetail(id));
    }
}
